//package keymove;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import java.lang.Integer;

public class Player
{
	private int width = 3, height = 10;
	private int currentX, currentY;
	private int destX, destY;
	private Color color = Color.CYAN;
	private boolean flagUp = false, flagDown = false, flagLeft = false, flagRight = false;
	
	/**
	 * Constructor of Player, with parent frame dimension as params.
	 * 
	 * @param x Parent frame width
	 * @param y Parent frame height
	 */
	public Player(int x, int y)
	{
		destX = x;
		destY = y;
		currentX = x>>1; // less one bit
		currentY = y>>1;
	}
	
	public void setUp(Boolean value)
	{
		flagUp = value;
	}
	
	public void setDown(Boolean value)
	{
		flagDown = value;
	}
	
	public void setLeft(Boolean value)
	{
		flagLeft = value;
	}
	
	public void setRight(Boolean value)
	{
		flagRight = value;
	}
	
	/**
	 * Sprite Status Update
	 */
	public void move()
	{
		if (flagRight)
		{
			if (destX > currentX + width)
			{
				currentX += 1;
			}
		}
		if (flagLeft)
		{
			if (currentX > 0)
			{
				currentX -= 1;
			}
		}
		if (flagUp)
		{
			if (currentY > 0)
			{
				currentY -= 1;
			}
		}
		if (flagDown)
		{
			if (destY > currentY + height)
			{
				currentY += 1;
			}
		}
	}
	
	public void randomv() 
	{		
		// randomize move by Class RandomGenerator
		int randomInt = RandomGenerator.nextInt(4);
		switch (randomInt)
		{
		case 0: currentX = currentX;
		case 1: currentX -= 1; 
		case 2: currentX += 1;
		case 3: currentY -= 1;
		case 4: currentY += 1;
		}
	}
	
	/**
	 * Drawing Player to Draw Graphic
	 * 
	 * @param g
	 */
	public void draw(Graphics g)
	{
		g.setColor(color);
		g.drawRect(currentX, currentY, width, height);
	}
}
